package cn.zwk;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws Exception {
        // 1. 创建FreeMarker配置
        Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
        cfg.setDirectoryForTemplateLoading(new File("F:\\zwk\\java\\projects\\excel_test\\src\\main\\resources\\templates"));
        cfg.setDefaultEncoding("UTF-8");

        // 2. 准备数据模型
        Map<String, Object> data = new HashMap<>();
        Map<String, Object> res = new HashMap<>();
        res.put("status", 200);
        res.put("data", Arrays.asList("success", "ok"));
        data.put("res", res);

        // 3. 加载模板
        Template template = cfg.getTemplate("check_result.ftl");

        // 4. 渲染输出到字符串
        StringWriter writer = new StringWriter();
        template.process(data, writer);

        // 5. 输出结果
        String result = writer.toString().trim();
        System.out.println("模板返回结果: " + result);
    }
}
